package com.adams.action.sorting;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;

import com.adams.action.view.ViewAction;
import com.adams.custom.page.util.ViewUtil;

public class SortingAction extends ViewAction{

	private static final long serialVersionUID = 1L;
	Logger logger = Logger.getLogger(ViewAction.class.getName());
	private String gridPanelId;

	private String searchPanelId;

	public String rowUp() throws Exception{
		logger.info("rowUp method run begin.");
		if (ViewUtil.isNuLLStr(gridPanelId))
		{
			gridPanelId = request.getParameter("gridPanelId");
		}
		if (ViewUtil.isNuLLStr(searchPanelId))
		{
			searchPanelId = request.getParameter("searchPanelId");
		}
		Map inputMap = ViewAction.requestParameterMap2Map(request);
		String paramStr = inputMap.get("data").toString();
		JSONObject data = JSONObject.fromObject(paramStr);
		JSONObject baseParams = (JSONObject)data.get("baseParams");
		String viewEventIdStr = inputMap.get("viewEventId").toString();
		
		Map map = viewParseService.Storting(viewEventIdStr,data);
		write(JSONObject.fromObject(map).toString());
		logger.info("rowUp method run end.");
		return null;
	}

	public String rowDown() throws Exception{
		logger.info("rowDown method run begin.");
		if (ViewUtil.isNuLLStr(gridPanelId))
		{
			gridPanelId = request.getParameter("gridPanelId");
		}
		if (ViewUtil.isNuLLStr(searchPanelId))
		{
			searchPanelId = request.getParameter("searchPanelId");
		}
		Map inputMap = ViewAction.requestParameterMap2Map(request);
		String paramStr = inputMap.get("data").toString();
		JSONObject data = JSONObject.fromObject(paramStr);
		JSONObject baseParams = (JSONObject)data.get("baseParams");
		String viewEventIdStr = inputMap.get("viewEventId").toString();
		
		Map map = viewParseService.Storting(viewEventIdStr,data);
		write(JSONObject.fromObject(map).toString());
		logger.info("rowDown method run end.");
		return null;
	}
	
	public String rowTop() throws Exception{
		logger.info("rowTop method run begin.");
		if (ViewUtil.isNuLLStr(gridPanelId))
		{
			gridPanelId = request.getParameter("gridPanelId");
		}
		if (ViewUtil.isNuLLStr(searchPanelId))
		{
			searchPanelId = request.getParameter("searchPanelId");
		}
		Map inputMap = ViewAction.requestParameterMap2Map(request);
		String paramStr = inputMap.get("data").toString();
		JSONObject data = JSONObject.fromObject(paramStr);
		JSONObject baseParams = (JSONObject)data.get("baseParams");
		String viewEventIdStr = inputMap.get("viewEventId").toString();
		
		Map map = viewParseService.Storting(viewEventIdStr,data);
		write(JSONObject.fromObject(map).toString());
		logger.info("rowTop method run end.");
		return null;
	}
	
	public String rowBottom() throws Exception{
		logger.info("rowBottom method run begin.");
		if (ViewUtil.isNuLLStr(gridPanelId))
		{
			gridPanelId = request.getParameter("gridPanelId");
		}
		if (ViewUtil.isNuLLStr(searchPanelId))
		{
			searchPanelId = request.getParameter("searchPanelId");
		}
		Map inputMap = ViewAction.requestParameterMap2Map(request);
		String paramStr = inputMap.get("data").toString();
		JSONObject data = JSONObject.fromObject(paramStr);
		String viewEventIdStr = inputMap.get("viewEventId").toString();
		
		Map map = viewParseService.Storting(viewEventIdStr,data);
		write(JSONObject.fromObject(map).toString());
		logger.info("rowBottom method run end.");
		return null;
	}
	
	public String getGridPanelId() {
		return gridPanelId;
	}

	public void setGridPanelId(String gridPanelId) {
		this.gridPanelId = gridPanelId;
	}

	public String getSearchPanelId() {
		return searchPanelId;
	}

	public void setSearchPanelId(String searchPanelId) {
		this.searchPanelId = searchPanelId;
	}
}
